package com.berrontech.asbog;

import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

/**
 * Create by levent8421 2021/4/9 21:30
 * SimpleWebChromeClient
 *
 * @author levent8421
 */
public class SimpleWebChromeClient extends WebChromeClient {
    private static final int MAX_PROGRESS = 100;
    private static final String TAG = "SimpleWebChromeClient";

    public interface WebViewProgressListener {
        /**
         * Call on web view loading progress changed
         *
         * @param view     view
         * @param progress progress
         * @param loaded   Loaded
         */
        void onProgressChanged(WebView view, int progress, boolean loaded);
    }

    public SimpleWebChromeClient(WebViewProgressListener progressListener) {
        this.progressListener = progressListener;
    }

    public final WebViewProgressListener progressListener;

    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        super.onProgressChanged(view, newProgress);
        if (this.progressListener != null) {
            this.progressListener.onProgressChanged(view, newProgress, newProgress >= MAX_PROGRESS);
        }
    }

    @Override
    public void onReceivedTitle(WebView view, String title) {
        super.onReceivedTitle(view, title);
        Log.i(TAG, "Receive title:" + title);
    }
}
